package com.xiaoyu.lanling.feature.moment.model

import `in`.srain.cube.request.JsonData
import `in`.srain.cube.views.list.ListItemTypedBase
import androidx.annotation.StringDef
import com.xiaoyu.base.model.User
import com.xiaoyu.lanling.feature.user.model.UserExtra
import com.xiaoyu.lanling.media.image.ImageLoadParam
import com.xiaoyu.lanling.media.image.UserImageLoadParam

class MomentItem constructor(jsonData: JsonData, @FeedSource val source: String) : ListItemTypedBase {

    companion object {
        const val SOURCE_PROFILE = "profile"
        const val SOURCE_SUBSCRIBE = "follow_feed"
        const val SOURCE_RECOMMEND = "feed"
        const val SOURCE_DETAIL = "moment_detail"
        const val SOURCE_PUBLISH = "follow_feed"

        @StringDef(SOURCE_PROFILE, SOURCE_SUBSCRIBE, SOURCE_SUBSCRIBE, SOURCE_DETAIL, SOURCE_PUBLISH)
        annotation class FeedSource

        fun createProfileMoment(jsonData: JsonData): MomentItem {
            return MomentItem(jsonData = jsonData, source = SOURCE_PROFILE)
        }

        fun createRecommendMoment(jsonData: JsonData): MomentItem {
            return MomentItem(jsonData = jsonData, source = SOURCE_RECOMMEND)
        }

        fun createSubscribeMoment(jsonData: JsonData): MomentItem {
            return MomentItem(jsonData = jsonData, source = SOURCE_SUBSCRIBE)
        }

        fun createDetailMoment(jsonData: JsonData): MomentItem {
            return MomentItem(jsonData = jsonData, source = SOURCE_DETAIL)
        }

        fun createPublishMoment(jsonData: JsonData): MomentItem {
            return MomentItem(jsonData = jsonData, source = SOURCE_PUBLISH)
        }
    }

    var accosted: Boolean = false
    val userJsonData = jsonData.optJson("user")
    val user = User.fromJson(userJsonData)
    val soliloquy: String = userJsonData.optString("soliloquy")
    val age = userJsonData.optString("age")
    val verified = userJsonData.optString("verify") == UserExtra.VerifyStatus.SUCCESS
    val userTag = userJsonData.optString("userTag")
    val vipIcon = jsonData.optJson("vipInfo").optString("icon")
    val feed = Feed.fromJson(jsonData.optJson("feed"))
    val avatarLoadParam = UserImageLoadParam.newBuilder().setUserAndDP(user, 54).build()
    val vipLoadParam: ImageLoadParam = ImageLoadParam.newBuilder().setEnableEmptyUrl(true).setUrl(vipIcon).setSizeInDP(24).build()

    override fun getViewType(): Int {
        return 0
    }
}